const mongoose = require('./db')
const state = mongoose.Schema({
    level: Number,//等级
    types: String,//维修类型
    address: String,//地点
    names:String,
    progress_id: {
        type: mongoose.Types.ObjectId,
        ref: 'types',
    },
    repair_applicant: String,//负责人
    processor_id: { //处理人
        type: mongoose.Types.ObjectId,
        ref: 'user'
    },
    phone: String,//手机号
    department: { //部门
        type: mongoose.Types.ObjectId,
        ref: 'department'
    },
    create_time: {//创建时间
        type: Date,
        default: new Date()
    },
    end_time: Date,//完成时间
    describe: {//描述
        type: String,
        default: ''
    },
    old_imgs: {//旧的照片
        type: Array,
    },
    new_imgs: {//修好的照片
        type: Array
    },
    grade_id: {
        type: mongoose.Types.ObjectId,
        ref: 'grades'
    },//评价
    repair_id: { //用户id（外键）
        type: mongoose.Types.ObjectId,
        ref: 'user'
    }
})
const types = mongoose.Schema({
    id:{
        type:Number, //工单状态类型
    },
    name: String//工单名称
})
const grades=mongoose.Schema({
    completion_quality:String,//完成质量
    corresponding_speed:String,//响应速度
    wei_speed:String,//维修进度
    grade_num:Number//评价数量
})


let StateModel = mongoose.model("state", state,'state')
let TypeModel = mongoose.model('types', types,'types')
let GradesModel=mongoose.model('grades',grades,'grades')
// TypeModel.create([{
//     id:1,
//     name:'待处理',
// },{id:2,name:'处理中'},{id:3,name:'待评价'},{id:4,name:'以完成'}])
// StateModel.create([{level:2,types:'空调',progress_id:'6426defece7156ca3c940843',repair_applicant:'闫鸿',address:'山西省吕梁市',processor_id:'64252e39a93ec1bf884de94f',phone:'18935167972',department:'64253cc635b0710c6c8a8e11',describe:'非常好',
// old_imgs:['http://127.0.0.1:3000/uploads/1680138980312.jpeg','http://127.0.0.1:3000/images/userdefault.webp'],grade:3,repair_id:'64252d9acb340faaab3b5634'},
// {level:3,types:'手机',progress_id:'6426defece7156ca3c940843',repair_applicant:'王波',address:'山西省吕梁市',processor_id:'64252e5ea93ec1bf884de95b',phone:'18935167972',department:'64253cc635b0710c6c8a8e11',describe:'非常好',
// old_imgs:['http://127.0.0.1:3000/uploads/1680138980312.jpeg','http://127.0.0.1:3000/images/userdefault.webp'],grade:4,repair_id:'64252d9acb340faaab3b5634'}
// ])
module.exports = { StateModel,TypeModel,GradesModel }